package com.wondedDream.controller.admin;

import com.wondedDream.model.MockExamQuestion;
import com.wondedDream.model.PracticeQuestion;
import com.wondedDream.service.PracticeQuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController(value = "adminPracticeQuestionController")
@RequestMapping("/api/practiceQuestions")
@Api(description = "管理端-练习信息")
public class PracticeQuestionController {

    @Autowired
    private PracticeQuestionService practiceQuestionService;

    // 创建新的练习问题
    @PostMapping("/")
    @ApiOperation(value = "创建新的练习问题")
    public PracticeQuestion createPracticeQuestion(@RequestBody PracticeQuestion question) {
        return  practiceQuestionService.savePracticeQuestion(question);
    }

    // 根据id删除练习问题
    @DeleteMapping("/{id}")
    @ApiOperation(value = "根据id删除练习问题")
    public void deletePracticeQuestion(@PathVariable Integer id) {
        practiceQuestionService.deletePracticeQuestion(id);
    }


    // 根据id修改练习问题
    @PutMapping("/{id}")
    @ApiOperation(value = "根据id修改练习问题")
    public PracticeQuestion updatePracticeQuestion(@PathVariable Integer id, @RequestBody PracticeQuestion practiceQuestion) {
        practiceQuestion.setId(id);
        return practiceQuestionService.updatePracticeQuestion(practiceQuestion);
    }



    // 获取练习问题信息
    @GetMapping("/{id}")
    @ApiOperation(value = "获取练习问题信息")
    public PracticeQuestion getPracticeQuestionById(@PathVariable Integer id) {
        return practiceQuestionService.getPracticeQuestionById(id);
    }

    // 获取某一课程下的练习问题列表
    @GetMapping("/byPracticeId/{practiceId}")
    @ApiOperation(value = "获取某一分类下的练习问题列表")
    public List<PracticeQuestion> getPracticeQuestionsByPracticeId(@PathVariable Integer practiceId) {
        return practiceQuestionService.getPracticeQuestionsByPracticeId(practiceId);
    }

    // 创建新的模考问题
    @PostMapping("/createMockExamQuestionByFileJson")
    @ApiOperation(value = "根据文件导入练习题库")
    public String createMockExamQuestionByFileJson(@RequestParam("localPath") String localPath,
                                                   @RequestParam("courseCategoryId") Integer courseCategoryId,
                                                   @RequestParam("practiceName") String practiceName) {
        practiceQuestionService.createMockExamQuestionByFileJson(localPath,courseCategoryId,practiceName);
        return "success";
    }
}